#include <iostream>
#include <stdlib.h>
#include <algorithm>

#include "libmri.h"

using namespace std;

int main (int argc, char **argv)
{
	shm_array_t *shm_calib = 0, *shm_k = 0, *shm_output = 0;
	char *output = 0;

	if (0 == shm_calib){
		if (get_shm_array("calib", &shm_calib)){
			perror("calib");
			return -1;
		}
	}

	if (0 == shm_k){
		if (get_shm_array("k", &shm_k)){
			perror("k");
			return -1;
		}
	}

	if (0 == output){
		output = strdup("output");
	}

	if (make_shm_array (output, shm_k, &shm_output)){
		perror(output);
		return -1;
	}

	cplxf *calib = (cplxf*) shm_calib->data.c;
	int csize[4] = {shm_calib->dims[0], shm_calib->dims[1],
	                shm_calib->dims[2], shm_calib->dims[3]};

	cplxf *k = (cplxf*) shm_k->data.c;
	int ksize[3] = {shm_k->dims[0], shm_k->dims[1], shm_k->dims[2]};

	cplxf *z = (cplxf*) shm_output->data.c;

	calib3d_atamul (z, calib, csize, k, ksize);

	return 0;
}
